﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using TerraExplorerX;
using Utilities;
using Entity;

namespace UI
{
    public partial class AttributeForm : KryptonForm
    {
        private string selectedLayerName = string.Empty;
        private ISGWorld61 sgworld;
        public AttributeForm(ISGWorld61 sgw)
        {
            InitializeComponent();
            this.sgworld = sgw;
        }
        public AttributeForm()
        {
            InitializeComponent();            
        }

        private void AttributeForm_Load(object sender, EventArgs e)
        {
            this.CboxLayer.Items.Add(ConfigurationManager.AppSettings["CRLayer"]);
            this.CboxLayer.Items.Add("医院");
            this.CboxLayer.Items.Add("消防");
            this.CboxLayer.Items.Add("校园道路");
            this.CboxLayer.SelectedIndex = 0;
            //PropertyQuery("5");
        }       

        private void kryptonComboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            this.selectedLayerName = this.CboxLayer.SelectedItem.ToString();
        }

        private void Btn_Query_Click(object sender, EventArgs e)
        {
            int key = 0;
            if (Tbox_Name.Text != null && Tbox_Name.Text != string.Empty)
            {
                key = Convert.ToInt32(Tbox_Name.Text);
            }
            PropertyQuery2(key);
        }

        private void PropertyQuery2(int key)
        {
            PropertyQuery pq = new PropertyQuery();
            EClassRoom cr = pq.Query(key);
            if (cr != null)
            {
                IPosition61 pos = sgworld.Creator.CreatePosition(cr.Lon, cr.Lat, cr.Alt, AltitudeTypeCode.ATC_TERRAIN_RELATIVE);
                //sgworld.Creator.CreateImageLabel(pos, Application.StartupPath+ @"\images\poi.png",
                    //null, 0, Description: cr.CRCode.ToString());
                ILabelStyle61 style = sgworld.Creator.CreateLabelStyle();
                style.TextColor = sgworld.Creator.CreateColor(255,0,0,255);
                ITerrainLabel61 imgLabel = sgworld.Creator.CreateLabel(pos,"知明1-"+cr.CRCode.ToString(), 
                    Application.StartupPath + @"\images\poi.png", style, 0, Description: cr.CRCode.ToString());
                sgworld.Navigate.FlyTo(imgLabel);
                //sgworld.ProjectTree.DeleteItem(sgworld.ProjectTree.FindItem(cr.CRCode.ToString())); 
                
            }
            else
            {
                MessageBox.Show("没有找到符合条件的结果！");
            }
        }
        

        private void PropertyQuery3(string key)
        {
            int itemID = sgworld.ProjectTree.FindItem(selectedLayerName);
            ILayer61 crLayer = sgworld.ProjectTree.GetLayer(itemID);
            
            if (key != string.Empty && key != null)
            {
                crLayer.Filter = "CRCode=" + key;
                crLayer.Streaming = true;
                crLayer.Refresh();
               
                //crLayer.Refresh();
            }
        }        
       

        private void AttributeForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

       
    }
}
